<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "collect".
 *
 * @property integer $uid
 * @property integer $aid
 */
class Collect extends \yii\db\ActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'collect';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['uid', 'aid'], 'required'],
            [['uid', 'aid'], 'integer']
        ];
    }

    public function getArticle() {
        return $this->hasOne(Article::className(), ['id' => 'aid']);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'uid' => '用户ID',
            'aid' => '文章ID',
        ];
    }

    public function check($aid) {
        $uid = Yii::$app->user->identity->id;
        $result = Collect::findOne(['uid' => $uid, 'aid' => $aid]);
        return $this->render('/widgets/collect', ['result' => $result, 'aid' => $aid]);
    }

}
